package com.augurit.common.base.action;

import java.util.Calendar;
import java.util.List;
import java.util.Map;

import com.augurit.common.syscode.service.ISysCodeService;
import com.augurit.common.syscode.web.form.SysCodeForm;
import com.augurit.common.system.util.WebContextUtils;


/**
 * 业务系统的 Action 基类，可在此处编写业务系统的公共属性或公共方法
 */
public class ProjBaseAction extends BaseAttachmentAction {
	
	/**
	 * 根据数据字典类型获取数据字典子项列表
	 * @param sysCodeService
	 * @param typeCode
	 * @return
	 */
	public List<SysCodeForm> getSysCodeItems(String typeCode, ISysCodeService sysCodeService){
		return sysCodeService.getItems(typeCode);
	}
	
	/**
	 * 根据数据字典类型获取数据字典子项列表，带缓存功能
	 * @param sysCodeService
	 * @param typeCode
	 * @return
	 */
	public List<SysCodeForm> getSysCodeItemsWithBuffer(String typeCode, ISysCodeService sysCodeService){
		Map<String, List<SysCodeForm>> sysCodeBuffer = WebContextUtils.getSysCodeBuffer(this.getApplication());
		if(sysCodeBuffer != null){
			List<SysCodeForm> items = sysCodeBuffer.get(typeCode);
			if(items == null || items.size() == 0){
				items = sysCodeService.getItems(typeCode);
				sysCodeBuffer.put(typeCode, items);
			}
			return items;
		}else
			return sysCodeService.getItems(typeCode);
	}
	public String getSysRealPath(){
		
		return (String)this.getRequest().getRealPath("");
	}
	public void setSysRealPath(String path){
		if(path != null){
			this.getRequest().getSession().setAttribute(WebContextUtils.SERVER_REAL_PATH, path);
		}
	}
	
	public String getSysVersion(){
		//return (String)this.getSession().getAttribute(WebContextUtils.SYS_VERSION);
		//获取系统年份
		Calendar calendar = Calendar.getInstance() ;
		Integer year = calendar.get(Calendar.YEAR);
		return year.toString();
	}
	public void setSysVersion(String version){
		if(version != null){
			this.getRequest().getSession().setAttribute(WebContextUtils.SYS_VERSION, version);
		}
	}
}
